package com.lockmem.setting;

import com.lockmem.Conf.ConfValue;
import com.lockmem.constants.MyActivity;
import com.lockmem.ctrl.CtrlService;
import com.lockmem.study.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class SettingActivity extends MyActivity {

	

	private ExpandableListView expandableListView = null;
	private String tag = "SettingActivity";

	// 群组名称
	private String[] group = new String[] { "学习计划设置", "学习量设置", "顺序", "模式设置",
			"软件开关", "皮肤选择", "当前版本" };
	// 好友名称
	private String[][] mainStr = new String[][] { { "本地资源", "网络题库" },
			{ "学习量" }, { "学习顺序" }, { "浏览模式", "答题模式" }, { "软件状态" },
			{ "更换皮肤" }, { "检查更新", "给开发者提建议" } };
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		this.finish();
		Log.v("1","onPause Setting");
		super.onPause();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if(keyCode==KeyEvent.KEYCODE_BACK){
			Intent intent = new Intent(this,StatisticActivity.class	);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
		}
		return super.onKeyDown(keyCode, event);
	}

	private String[][] viceStr;
	private QqAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(R.layout.activity_setting);
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
				R.layout.titlebar_setting);
		expandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
	}

	/**
	 * 初始化ListView
	 */
	private void initExpandableListView() {
		adapter = new QqAdapter(this, group, mainStr, viceStr);
		expandableListView.setAdapter(adapter);
		for (int i = 0; i < group.length; i++) {
			expandableListView.expandGroup(i);
		}
		// 消耗掉groupclick事件，防止点击放缩
		expandableListView.setOnGroupClickListener(new OnGroupClickListener() {

			@Override
			public boolean onGroupClick(ExpandableListView parent, View v,
					int groupPosition, long id) {
				// TODO Auto-generated method stub
				return true;
			}
		});

		// 子菜单
		expandableListView.setOnChildClickListener(new OnChildClickListener() {

			@Override
			public boolean onChildClick(ExpandableListView arg0, View arg1,
					int groupPosition, int childPosition, long arg4) {
				adapter.setGCid(groupPosition, childPosition);
				switch (groupPosition) {
				case 0:
					if (childPosition == 0) {
						setLocalRes();
					} else if (childPosition == 1) {
						setNetRes();
					}
					break;
				case 1:
					if (childPosition == 0) {
						setCount();
					}
					break;
				case 2:
					if (childPosition == 0) {
						setOrder();
					}
					break;
				case 3:
					if (childPosition == 0) {
						setScanMode();
					} else if (childPosition == 1) {
						setAnsMode();
					}
					break;
				case 4:
					if (childPosition == 0) {
						touchSwitch();
					}
					break;
				case 5:
					if (childPosition == 0) {
						setSkin();
					}
					break;
				case 6:
					if (childPosition == 0) {
						checkupdate();
					} else if (childPosition == 1) {
						submit_suggestion();
					}
				}
				return false;
			}
		});
	}

	private void setAnsMode() {
		// TODO Auto-generated method stub
		inflater = getLayoutInflater();
		View layout = inflater.inflate(R.layout.modesetting,
				(ViewGroup) findViewById(R.id.dialog));
		final Spinner spStart = (Spinner) layout
				.findViewById(R.id.SpinnerStart);
		final Spinner spEnd = (Spinner) layout.findViewById(R.id.spinnerEnd);
		BaseAdapter ba = new BaseAdapter() {
			// 一共24个选项
			public int getCount() {
				return 25;
			}

			public Object getItem(int position) {
				return null;
			}

			public long getItemId(int position) {
				return 0;
			}

			public View getView(int position, View convertView, ViewGroup parent) {
				// 动态生成每个下拉项对应的View，每个下拉项View由LinearLayout
				// 一个TextView构成
				// 初始化LinearLayout
				LinearLayout ll = new LinearLayout(SettingActivity.this);
				ll.setOrientation(LinearLayout.HORIZONTAL);
				TextView tv = new TextView(SettingActivity.this);
				tv.setText(position < 24 ? String.valueOf(position) + ":00"
						: "全天");
				tv.setTextColor(getResources().getColor(R.color.black));
				tv.setTextSize(19);
				ll.addView(tv);
				return ll;
			}
		};
		spStart.setAdapter(ba);
		spEnd.setAdapter(ba);
		spStart.setOnItemSelectedListener(new OnItemSelectedListener() {
			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				Log.v(tag, String.valueOf(arg2 * 100 + arg3));
				if (arg2 == 24)// 开始时间选中全天，则结束时间也选中全天
					spEnd.setSelection(24);
				else if (arg2 < 24 && spEnd.getSelectedItemPosition() == 24)// 开始时间取消全天，结束时间也取消全天
					spEnd.setSelection(23);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
			}
		});
		spEnd.setOnItemSelectedListener(new OnItemSelectedListener() {
			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if (arg2 == 24)// 开始时间选中全天，则结束时间也选中全天
					spStart.setSelection(24);
				else if (arg2 < 24 && spStart.getSelectedItemPosition() == 24)// 开始时间取消全天，结束时间也取消全天
					spStart.setSelection(0);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
			}
		});
		int[] is = ser.getModeTime();
		if (is[0] == 24) {
			spStart.setSelection(0);
			spEnd.setSelection(0);
		} else if (is[0] == 0) {
			spStart.setSelection(24);
			spEnd.setSelection(24);
		} else {
			spStart.setSelection(is[1]);
			spEnd.setSelection(is[0]);
		}
		new AlertDialog.Builder(this).setTitle("设置答题模式时间段").setView(layout)
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						int[] i = { spEnd.getSelectedItemPosition(),
								spStart.getSelectedItemPosition() };
						if (i[0] == i[1]) {
							if (i[0] != 24)
								i[0] = i[1] = 24;
							else
								i[0] = i[1] = 0;
						}
						ser.setModeTime(i);
						changeViceStr();
					}
				}).setNegativeButton("取消", null).show();

	}

	/**
	 * 切换浏览模式和答题模式的文字
	 */
	protected void changeViceStr() {
		// TODO Auto-generated method stub
		adapter.setViceStr(getModeStr());
		adapter.notifyDataSetChanged();
	}

	private void submit_suggestion() {
		// TODO Auto-generated method stub
		if (isOpenNetwork()) {
			final EditText et = new EditText(this);

			new AlertDialog.Builder(this)
					.setTitle("建议与意见")
					.setView(et)
					.setPositiveButton("确定",
							new DialogInterface.OnClickListener() {

								@Override
								public void onClick(DialogInterface dialog,
										int which) {
									// TODO Auto-generated method stub
									String content = et.getText().toString()
											.trim();
									if (!content.equals("")) {
										// 建立Intent对象
										String[] reciver = new String[] { "zhengduoutan@qq.com" };
										String[] mySbuject = new String[] { "Lockmem建议" };
										String myCc = "cc";
										String mybody = content;
										Intent myIntent = new Intent(
												android.content.Intent.ACTION_SEND);
										myIntent.setType("plain/text");
										myIntent.putExtra(
												android.content.Intent.EXTRA_EMAIL,
												reciver);
										myIntent.putExtra(
												android.content.Intent.EXTRA_CC,
												myCc);
										myIntent.putExtra(
												android.content.Intent.EXTRA_SUBJECT,
												mySbuject);
										myIntent.putExtra(
												android.content.Intent.EXTRA_TEXT,
												mybody);
										startActivity(Intent.createChooser(
												myIntent, "发送邮件"));
									}
								}
							}).show();
			Log.v(tag, "after after");

		} else {
			Toast.makeText(this, "请先开启网络", Toast.LENGTH_SHORT).show();
		}

	}

	private void checkupdate() {
		// TODO Auto-generated method stub
		if (isOpenNetwork()) {
			new AlertDialog.Builder(this).setTitle("检查更新")
					.setMessage("你安装的已是最新版本！").setPositiveButton("确定", null)
					.show();
		} else {
			Toast.makeText(this, "请先开启网络", Toast.LENGTH_SHORT).show();
		}
	}

	private void setSkin() {
		// TODO Auto-generated method stub
		final String[] items = new String[] { "玫瑰之恋","蓝色星晴" };
		which_temp = ser.getSkin()%10;
		final int old_which = which_temp;
		new AlertDialog.Builder(this)
				.setTitle("设置皮肤")
				.setSingleChoiceItems(items, which_temp,
						new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								// TODO Auto-generated method stub
								which_temp = which;
							}
						}).setPositiveButton("确定", new DialogInterface.OnClickListener() {
							
							@Override
							public void onClick(DialogInterface dialog, int which) {
								// TODO Auto-generated method stub
								ser.setSkin(which_temp);
								if(old_which != which_temp){
									if(which_temp==ConfValue.Skin_Blue){
										turnBoyTheme(R.id.setlay, 3);										
									}
									else if(which_temp==ConfValue.Skin_Pink){
										turnGirlTheme(R.id.setlay, 3);
									}
								}
								changeViceStr(ser.getSkinStr());
							}
						})
				.setNegativeButton("取消", null).show();
	}

	protected void refreshSkin() {
		// TODO Auto-generated method stub
		Intent in = new Intent(this,SettingActivity.class);
		in.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(in);
	}

	private void setScanMode() {
		LayoutInflater inflater = getLayoutInflater();
		View layout = inflater.inflate(R.layout.modesetting,
				(ViewGroup) findViewById(R.id.dialog));
		final Spinner spStart = (Spinner) layout
				.findViewById(R.id.SpinnerStart);
		final Spinner spEnd = (Spinner) layout.findViewById(R.id.spinnerEnd);
		BaseAdapter ba = new BaseAdapter() {
			// 一共24个选项
			public int getCount() {
				return 25;
			}

			public Object getItem(int position) {
				return null;
			}

			public long getItemId(int position) {
				return 0;
			}

			public View getView(int position, View convertView, ViewGroup parent) {
				// 动态生成每个下拉项对应的View，每个下拉项View由LinearLayout
				// 一个TextView构成
				// 初始化LinearLayout
				LinearLayout ll = new LinearLayout(SettingActivity.this);
				ll.setOrientation(LinearLayout.HORIZONTAL);
				TextView tv = new TextView(SettingActivity.this);
				tv.setText(position < 24 ? String.valueOf(position) + ":00"
						: "全天");
				tv.setTextColor(getResources().getColor(R.color.black));
				tv.setTextSize(19);
				ll.addView(tv);
				return ll;
			}
		};
		spStart.setAdapter(ba);
		spEnd.setAdapter(ba);
		spStart.setOnItemSelectedListener(new OnItemSelectedListener() {
			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				Log.v(tag, String.valueOf(arg2 * 100 + arg3));
				if (arg2 == 24)// 开始时间选中全天，则结束时间也选中全天
					spEnd.setSelection(24);
				else if (arg2 < 24 && spEnd.getSelectedItemPosition() == 24)// 开始时间取消全天，结束时间也取消全天
					spEnd.setSelection(23);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
			}
		});
		spEnd.setOnItemSelectedListener(new OnItemSelectedListener() {
			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if (arg2 == 24)// 开始时间选中全天，则结束时间也选中全天
					spStart.setSelection(24);
				else if (arg2 < 24 && spStart.getSelectedItemPosition() == 24)// 开始时间取消全天，结束时间也取消全天
					spStart.setSelection(0);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
			}
		});

		spStart.setSelection(ser.getModeTime()[0]);
		spEnd.setSelection(ser.getModeTime()[1]);

		new AlertDialog.Builder(this).setTitle("设置浏览模式时间段").setView(layout)
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						int[] i = { spStart.getSelectedItemPosition(),
								spEnd.getSelectedItemPosition() };
						if (i[0] == i[1]) {
							if (i[0] == 24)
								i[0] = i[1] = 24;
							else
								i[0] = i[1] = 0;
						}
						ser.setModeTime(i);
						changeViceStr();
					}
				}).setNegativeButton("取消", null).show();
	}

	private void setNetRes() {
		if (isOpenNetwork()) {
			new AlertDialog.Builder(this).setTitle("下载网络资源")
					.setMessage("暂无网络资源！").setPositiveButton("确定", null).show();
		} else {
			Toast.makeText(this, "请先开启网络", Toast.LENGTH_SHORT).show();
		}
	}

	private void setOrder() {
		// TODO Auto-generated method stub
		final String items[] = { "正序", "逆序", "乱序" };
		which_temp = ser.getOrder();
		new AlertDialog.Builder(this)
				.setTitle("设置学习顺序")
				.setSingleChoiceItems(items, which_temp,
						new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								// TODO Auto-generated method stub
								which_temp = which;
							}
						})
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						ser.setOrder(which_temp);
						changeViceStr(ser.getOrderStr());
					}
				}).setNegativeButton("取消", null).show();
	}

	/**
	 * 对网络连接状态进行判断
	 * 
	 * @return true, 可用； false， 不可用
	 */
	private boolean isOpenNetwork() {
		ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		if (connManager.getActiveNetworkInfo() != null) {
			return connManager.getActiveNetworkInfo().isAvailable();
		}

		return false;
	}

/*	private void setChEn() {
		// TODO Auto-generated method stub
		final String items[] = { "中译英", "英译中" };
		which_temp = ser.getChEn() == ConfValue.CE_CtoE ? 0 : 1;
		new AlertDialog.Builder(this)
				.setTitle("设置中英译模式")
				.setSingleChoiceItems(items, which_temp,
						new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								// TODO Auto-generated method stub
								which_temp = which;
							}
						})
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						ser.setChEn(which_temp == 0 ? ConfValue.CE_CtoE
								: ConfValue.CE_EtoC);
						changeViceStr(ser.getChEnStr());

					}
				}).setNegativeButton("取消", null).show();
	}*/

	private void setCount() {
		// TODO Auto-generated method stub
		final String items[] = { "每次1个", "每次2个", "每次3个", "每次4个", "每次5个",
				"每次6个", "每次7个", "每次8个", "每次9个", "每次10个" };
		which_temp = ser.getCount() - 1;
		new AlertDialog.Builder(this)
				.setTitle("设置学习量")
				// .setIcon(android.R.drawable.ic_input_add)
				.setSingleChoiceItems(items, which_temp,
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								which_temp = which;
							}
						})
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						ser.setCount(which_temp + 1);
						changeViceStr("每次" + (which_temp + 1) + "个");
					}
				}).setNegativeButton("取消", null).show();
	}

	private void changeViceStr(String str) {
		adapter.setViceStr(str);
		adapter.notifyDataSetChanged();
	}

	private void initViceStr() {
		// TODO Auto-generated method stub
		viceStr = new String[mainStr.length][];
		viceStr[0] = new String[] { ser.getCurrentResourceStr() };
		viceStr[1] = new String[] { "每次" + ser.getCount() + "个" };
		viceStr[2] = new String[] { ser.getOrderStr() };
		String[] ModeStr = getModeStr();
		viceStr[3] = new String[] { ModeStr[0], ModeStr[1] };
		viceStr[4] = new String[] { ser.getSwitchStr() };
		viceStr[5] = new String[] { ser.getSkinStr() };
		viceStr[6] = new String[] { "" + ser.getCurrentVision() };
	}

	/**
	 * 设置时间模式的两个按钮的文字
	 */
	private String[] getModeStr() {
		String[] ModeStr = new String[2];
		int[] scanTime = ser.getModeTime();
		if (scanTime[0] != scanTime[1]) {
			ModeStr[0] = String.format("%d:00~%d:00", scanTime[0], scanTime[1]);
			ModeStr[1] = String.format("%d:00~%d:00", scanTime[1], scanTime[0]);
		} else if (scanTime[0] == scanTime[1]) {
			if (scanTime[0] == 0) {
				ModeStr[0] = "不浏览";
				ModeStr[1] = "全天";
			} else if (scanTime[0] == 24) {
				ModeStr[0] = "全天";
				ModeStr[1] = "不答题";
			}
		}
		return ModeStr;
	}

	/**
	 * 用于记录用户做的选项改变
	 */
	private int which_temp;

	/**
	 * 本地资源修改
	 */
	private void setLocalRes() {
		final String[] items = ser.getLocalResNames();
		int currentItem = ser.getCurrentResNum();
		which_temp = currentItem;
		new AlertDialog.Builder(this)
				.setTitle("设置学习资料")
				.setSingleChoiceItems(items, currentItem,
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								// TODO Auto-generated method stub
								which_temp = which;
							}
						}).setPositiveButton("确定", new DialogInterface.OnClickListener() {
							
							@Override
							public void onClick(DialogInterface dialog, int which) {
								// TODO Auto-generated method stub
								ser.setCurrentResNum(which_temp);
							}
						})
				.setNegativeButton("取消", null).show();
	}

	/**
	 * 软件开关
	 */
	private void touchSwitch() {
		// TODO Auto-generated method stub
		// 开关按钮上写的开，说明用户想关闭
		final String items[] = { "关闭", "开启" };
		which_temp = ser.getSwitch() == ConfValue.switch_off ? 0 : 1;
		new AlertDialog.Builder(this)
				.setTitle("软件开关")
				// .setIcon(android.R.drawable.ic_input_add)
				.setSingleChoiceItems(items, which_temp,
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								which_temp = which;
							}
						})
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						if (which_temp == 0) {
							ser.setSwitch(ConfValue.switch_off);
						} else {
							ser.setSwitch(ConfValue.switch_on);
						}
						changeViceStr(ser.getSwitchStr());
					}
				}).setNegativeButton("取消", null).show();
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub
		initViceStr();
		// 配置适配器
		initExpandableListView();
	}
	
	@Override
	public void setTheme() {
		// TODO Auto-generated method stub
		if(ser.getSkin()==ConfValue.Skin_Pink)
			return ;	
		turnBoyTheme(R.id.setlay, 4);
	}
	
	private class QqAdapter extends BaseExpandableListAdapter {

		@Override
		public void notifyDataSetChanged() {
			// TODO Auto-generated method stub
			super.notifyDataSetChanged();
		}

		private String[] group = null;
		private String[][] mainStr = null;
		private Context context = null;
		private LayoutInflater inflater = null;
		private String[][] viceStr = null;

		public QqAdapter(Context context, String[] group, String[][] mainStr,
				String[][] viceStr) {
			this.group = group;
			this.context = context;
			inflater = LayoutInflater.from(context);
			this.mainStr = mainStr;
			this.viceStr = viceStr;
		}

		/**
		 * 取得子菜单内容
		 */
		@Override
		public Object getChild(int arg0, int arg1) {
			return mainStr[arg0][arg1];
		}

		/**
		 * listview的子项被点击时会设置
		 */
		private int gid;
		private int cid;
		public void setGCid(int gid,int cid){
			this.gid =gid;
			this.cid =cid;
		}
		
		
		/**
		 * 取得子菜单ID
		 */
		@Override
		public long getChildId(int arg0, int arg1) {
			return arg1;
		}

		/**
		 * 设置子菜单列表详情
		 */
		@Override
		public View getChildView(int groupPosition, int childPosition,
				boolean arg2, View convertView, ViewGroup arg4) {
			// 配置适配器
			convertView = inflater.inflate(R.layout.listview_child_item, null);
			if(ser.getSkin() != ConfValue.Skin_Pink){
				turnBoyTheme(convertView, 0);
			}
			// 取得组件
			TextView textView = (TextView) convertView
					.findViewById(R.id.listview_child_name);
			// 设置组件内容
			textView.setText(getChild(groupPosition, childPosition).toString());
			if (viceStr.length > groupPosition
					&& viceStr[groupPosition].length > childPosition) {
				TextView textView2 = (TextView) convertView
						.findViewById(R.id.listview_child_trends);
				// 当前选项
				textView2.setText(viceStr[groupPosition][childPosition]);
			}

			return convertView;
		}

		/**
		 * 根据组ID取得子菜单个数
		 */
		@Override
		public int getChildrenCount(int groupPosition) {
			return mainStr[groupPosition].length;
		}

		/**
		 * 取得分组情况
		 */
		@Override
		public Object getGroup(int groupPosition) {
			return group[groupPosition];
		}

		/**
		 * 取得分组个数
		 */
		@Override
		public int getGroupCount() {
			return group.length;
		}

		/**
		 * 取得分组ID
		 */
		@Override
		public long getGroupId(int groupPosition) {
			return groupPosition;
		}

		/**
		 * 设置分组详情
		 */
		@Override
		public View getGroupView(int groupPosition, boolean isExpanded,
				View convertView, ViewGroup arg3) {
			// 配置适配器
			convertView = inflater.inflate(R.layout.listview_group_item, null);
			
			if(ser.getSkin()!=ConfValue.Skin_Pink){
				turnBoyTheme(convertView, 2);
			}
			
			TextView textView = (TextView) convertView
					.findViewById(R.id.listview_group_name);
			textView.setText(getGroup(groupPosition).toString());
			// 设置每组人数
			TextView tv = (TextView) convertView
					.findViewById(R.id.listview_group_num);
			tv.setText("[" + getChildrenCount(groupPosition) + "]");
			// 设置图片
			ImageView imageView = (ImageView) convertView
					.findViewById(R.id.listview_image);
			imageView.setImageResource(R.drawable.ic_launcher);
			// 如果打开菜单
			if (isExpanded) {
				imageView.setImageResource(R.drawable.ic_launcher);
			}

			return convertView;
		}

		/**
		 * 组和子元素是否持有稳定的ID
		 */
		@Override
		public boolean hasStableIds() {
			return true;
		}

		/**
		 * 子选项是否可以选择
		 */
		@Override
		public boolean isChildSelectable(int arg0, int arg1) {
			// TODO Auto-generated method stub
			return true;
		}
		
		public void setViceStr(String str){
			viceStr[gid][cid] = str;
		}
		/**
		 * 更新答题模式与浏览模式文字
		 * @param modeStr
		 */
		public void setViceStr(String[] modeStr) {
			// TODO Auto-generated method stub
			viceStr[gid][0] = modeStr[0];
			viceStr[gid][1] = modeStr[1];
		}

	}
}
